package com.kaiwu.tc.web;

import com.kaiwu.tc.config.AppConfig;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;

public class MyWebApplicationInitializer implements WebApplicationInitializer {
    public void onStartup(ServletContext servletContext) {
        System.out.println("初始化 MyWebApplicationInitializer。。。");
        AnnotationConfigWebApplicationContext ac = new AnnotationConfigWebApplicationContext();
        ac.register(AppConfig.class);

        DispatcherServlet servlet = new DispatcherServlet(ac);
        ServletRegistration.Dynamic dynamic = servletContext.addServlet("/app", servlet);
        dynamic.setLoadOnStartup(1);
        dynamic.addMapping("/*");
    }
}
